/***********************************************************
 * Product Name: ExcelQuicker
 * Copyright (c)2005, Eunge
 * Author: Eunge
 * Web Site: www.eudev.net
 * Mail/MSN: eudev.net@yeah.net
 * ********************************************************/
using System;
using System.Collections;

namespace ExcelQuicker.Framework
{
	/// <summary>
	/// <br>Base class of multi-series chart. </br>
	/// <br>What's meaning of multi-series chart?</br>
	/// <br>A chart can show and analyze more than one data column.</br>
	/// </summary>
	abstract public class EQSeriesChart: EQChart 
	{
		private int mLabelColumnIndex = DefaultInt;
		private Hashtable mDataColumnIndexs = new Hashtable();

		/// <summary>
		/// Get a hash table with multi-series data column setting
		/// </summary>
		protected Hashtable DataColumnIndexs
		{
			get
			{
				return this.mDataColumnIndexs;
			}
		}

		/// <summary>
		/// Set/Get column index of label
		/// </summary>
		public int LabelColumnIndex
		{
			get
			{
				return this.mLabelColumnIndex;
			}
			set
			{
				this.mLabelColumnIndex = value;
			}
		}

		/// <summary>
		/// Add a new series data column binding
		/// </summary>
		/// <param name="index">Column index of binding in the datatable object</param>
		/// <param name="text">Display title</param>
		public void AddDataColumnIndex(int index, string text)
		{
			if(this.mDataColumnIndexs.ContainsKey(index))
				return;
			this.mDataColumnIndexs.Add(index, text);
		}

		/// <summary>
		/// Set a series data column binding
		/// </summary>
		/// <param name="index">Column index of binding in the datatable object</param>
		/// <param name="text">Display title</param>
		public void SetDataColumnIndex(int index, string text)
		{
			if(!this.mDataColumnIndexs.ContainsKey(index))
				return;
			this.mDataColumnIndexs[index] = text;
		}

		/// <summary>
		/// Remove a series data column binding
		/// </summary>
		/// <param name="index">Column index of binding in the datatable object</param>
		public void RemoveAt(int index)
		{
			if(this.mDataColumnIndexs.ContainsKey(index))
				this.mDataColumnIndexs.Remove(index);
		}

		/// <summary>
		/// Remove all series data column binding
		/// </summary>
		public void Remove()
		{
			this.mDataColumnIndexs.Clear();
		}

		/// <summary>
		/// Bind this object to a TableBase obejct. It will do column name check in this function.
		/// </summary>
		/// <param name="table"></param>
		protected internal override void RenderTableBase(EQTableBase table)
		{
			base.RenderTableBase(table);	//Call base function

			int intColumnCount = table.Table.Columns.Count;
			if(this.mLabelColumnIndex != DefaultInt)
			{
				if(this.mLabelColumnIndex >= intColumnCount)
					throw new EQException("EQ1033", new string[]{this.GetType().ToString(), this.mLabelColumnIndex.ToString(EQKit.ObjNumberFormatInfo), intColumnCount.ToString(EQKit.ObjNumberFormatInfo)});
			}

			IDictionaryEnumerator objIDictionaryEnumerator = this.mDataColumnIndexs.GetEnumerator();
			while(objIDictionaryEnumerator.MoveNext())
			{
				int intDataColumnIndex = (int)objIDictionaryEnumerator.Key;
				if(intDataColumnIndex != DefaultInt)
				{
					if(intDataColumnIndex >= intColumnCount)
					{
						Type type = this.GetType();
						throw new EQException("EQ1034", new string[]{type.ToString(), intDataColumnIndex.ToString(EQKit.ObjNumberFormatInfo), intColumnCount.ToString(EQKit.ObjNumberFormatInfo)});
					}
				}
			}
		}
	}
}
